/* vue */
import { Ref, ref } from "vue";
import { EmitFn } from 'vue/types/v3-setup-context';
/* model */
import { SettingTableEventEnum } from "src/modules/setting/gpt/model";

function useSettingListTable<T extends Record<string, any>>(emit: EmitFn) {
  
  const multipleSelection: Ref<T[]> = ref([])
  
  const handleSelectionChange = (value: T[] = []) => {
    multipleSelection.value = value
    emit(SettingTableEventEnum.ChangeSelection, value)
  }
  
  const getMultipleSelection = () => {
    return multipleSelection.value
  }
  
  const handlerSortChange = (value: { prop?: any, order?: any }) => {
    emit(SettingTableEventEnum.SortChange, value)
  }
  
  const clearMultipleSelection = () => {
    handleSelectionChange()
  }
  
  return {
    multipleSelection,
    handleSelectionChange,
    handlerSortChange,
    getMultipleSelection,
    clearMultipleSelection
  }
}

export {
  useSettingListTable
}
